<?php
/**
 * symfony3 - TaskController.php
 * Created by PhpStorm.
 * User: mac
 * Date: 6/11/16
 * Time: 10:48
 * Initial version by: mac
 * Initial version creation at: 6/11/16 10:48
 */
namespace Chap12Bundle\Controller;

use Chap12Bundle\Entity\Task;
use Chap12Bundle\Forms\TaskType;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class TaskController extends Controller
{

	/**
	 * @Route("/t")
	 */
	public function indexAction()
	{
		echo 111;
	}


	/**
	 * @Route("/task/new2")
	 */
	public function new2Action()
	{
		$task = new Task();

		$form = $this->createForm(TaskType::class, $task);


		if ($form->isValid()) {

			// get data
			$form->get("dueDate")->getData();

			$task = $form->getData();

			// set data
			$form->get('dueDate')->setData(new \DateTime());

			$em = $this->getDoctrine()->getManager();
			$em->persist($task);
			$em->flush();

			return $this->redirectToRoute("task_success");
		}


		$assign = array(
			'form' => $form->createView()
		);

		return $this->render('Chap12Bundle:Default:new.html.twig', $assign);
	}





}